package cn.jdy.xzgaj.web;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import cn.jdy.anquan.service.CompanySafeService;
import cn.jdy.common.ctrl.BaseCtrl;
import cn.jdy.plugins.service.AdviceService;
import cn.jdy.plugins.service.BulletinService;
import cn.jdy.plugins.service.CitiesService;
import cn.jdy.plugins.service.CompanyService;
import cn.jdy.plugins.service.DocService;
import cn.jdy.plugins.service.NewspService;
import cn.jdy.plugins.service.RemoteAssociationsService;
import cn.jdy.plugins.service.ResearchService;
import cn.jdy.plugins.service.WorksService;
import cn.jdy.xzgaj.service.XzgajAssociationsService;
import cn.jdy.xzgaj.service.XzgajNewsService;

/**
 * 网站首页
 *
 * @author yuyf
 * @date 2014-03-12
 */
@RestController
@RequestMapping("/")
public class XzgajIndexCtrl extends BaseCtrl {

	@Autowired
	private CompanySafeService companySafeService; 
	
	@Autowired
	private CompanyService companyService;
	
	@Autowired
    private XzgajNewsService newsService;
	
	@Autowired
    private NewspService newspService;
	
	@Autowired
    private DocService docService;
	
	@Autowired
	  private XzgajAssociationsService associationsService;
	
	@Autowired
	  private RemoteAssociationsService remoteAssociationsService;
	
	@Autowired
	  private WorksService worksService;
	
	@Autowired
	  private BulletinService bulletinService;
	
	@Autowired
	  private ResearchService researchService;
	
	@Autowired
	  private AdviceService adviceService;
	@Autowired
	private CitiesService citiesService;
	
	/**
   * 首页-处理老链接
   */
//  @RequestMapping("index.html")
//  public ModelAndView forIndexold() {
//    return new ModelAndView("redirect:");// 将之前index.html 的权重传递给域名
//  }
// 

	  /**
	   * 临时
		 * 首页
		
		@RequestMapping("/index")
		public ModelAndView indexes() {
			ModelAndView mv = new ModelAndView("/index.jsp");
			return mv;
		} */
			
	/**
	 * 市局
	 * 
	 * 首页
	 */
	@RequestMapping("/index.html")
	public ModelAndView index() {
		ModelAndView mv = new ModelAndView("/index.jsp");
		
		Date datetime = new Date();
		int weekdays = datetime.getDay();
		mv.addObject("weekdays",weekdays);//日一二三四五六=0123456
		
		String dutyname=this.associationsService.getduty();    //add with daihu   2016-11-1 获取今日值班数据，襄州使用
		//mv.addObject("dutyname",dutyname);
		session.setAttribute("dutyname", dutyname);
		

		String name1="zwpcs",name2="xwpcs",name3="sgpcs",name4="chpcs",name5="zjpcs",name6="yspcs",name7="zjjpcs",name8="sqpcs",name9="hlpcs",name10="gypcs",name11="lwpcs",name12="hppcs",name13="hjpcs";
		long[] cnt=new long[13];
		// cnt[0]+cnt[1]=cnt指挥中心？？？只能直接新增zhzx
		cnt[0]=this.associationsService.autils(name1);
		cnt[1]=this.associationsService.autils(name2);
		cnt[2]=this.associationsService.autils(name3);
		cnt[3]=this.associationsService.autils(name4);
		cnt[4]=this.associationsService.autils(name5);
		cnt[5]=this.associationsService.autils(name6);
		cnt[6]=this.associationsService.autils(name7);
		cnt[7]=this.associationsService.autils(name8);
		cnt[8]=this.associationsService.autils(name9);
		cnt[9]=this.associationsService.autils(name10);
		cnt[10]=this.associationsService.autils(name11);
		cnt[11]=this.associationsService.autils(name12);
		cnt[12]=this.associationsService.autils(name13);
		
		//
		// 顺序对应14个派出所
		int[] index={0,1,2,3,4,5,6,7,8,9,10,11,12};
		// 从小到大
		for(int i=0;i<cnt.length-1;i++){   
               for(int j=i+1;j<cnt.length;j++){   
                   if (cnt[i]>cnt[j]){   
                       long temp=cnt[i];   
                       cnt[i]=cnt[j];   
                       cnt[j]=temp; 
                       //下标
                       int tep=index[i];
                       index[i]=index[j];
                       index[j]=tep;
                  }   
            }  
       }  
		mv.addObject("first",cnt[12]);//最大数
		mv.addObject("firsta",this.aautils(index[12]));//对应单位名称
		mv.addObject("second",cnt[11]);
		mv.addObject("seconda",this.aautils(index[11]));
		mv.addObject("third",cnt[10]);
		mv.addObject("thirda",this.aautils(index[10]));
		mv.addObject("forth",cnt[9]);
		mv.addObject("fortha",this.aautils(index[9]));
		mv.addObject("fifth",cnt[8]);
		mv.addObject("fiftha",this.aautils(index[8]));
		mv.addObject("sixth",cnt[7]);
		mv.addObject("sixtha",this.aautils(index[7]));
		mv.addObject("seventh",cnt[6]);
		mv.addObject("seventha",this.aautils(index[6]));
		mv.addObject("eighth",cnt[5]);
		mv.addObject("eightha",this.aautils(index[5]));
		mv.addObject("ninth",cnt[4]);
		mv.addObject("nintha",this.aautils(index[4]));
		mv.addObject("tenth",cnt[3]);
		mv.addObject("tentha",this.aautils(index[3]));
		mv.addObject("eleventh",cnt[2]);
		mv.addObject("eleventha",this.aautils(index[2]));
		mv.addObject("twelfth",cnt[1]);
		mv.addObject("twelftha",this.aautils(index[1]));
		mv.addObject("thirteenth",cnt[0]);
		mv.addObject("thirteentha",this.aautils(index[0]));
//		mv.addObject("forteenth",cnt[0]);
//		mv.addObject("forteentha",this.aautils(index[0]));
		
		long[] bcnt=new long[13];
		// cnt[0]+cnt[1]=cnt指挥中心？？？只能直接新增zhzx
		bcnt[0]=this.associationsService.autilslev(name1);
		bcnt[1]=this.associationsService.autilslev(name2);
		bcnt[2]=this.associationsService.autilslev(name3);
		bcnt[3]=this.associationsService.autilslev(name4);
		bcnt[4]=this.associationsService.autilslev(name5);
		bcnt[5]=this.associationsService.autilslev(name6);
		bcnt[6]=this.associationsService.autilslev(name7);
		bcnt[7]=this.associationsService.autilslev(name8);
		bcnt[8]=this.associationsService.autilslev(name9);
		bcnt[9]=this.associationsService.autilslev(name10);
		bcnt[10]=this.associationsService.autilslev(name11);
		bcnt[11]=this.associationsService.autilslev(name12);
		bcnt[12]=this.associationsService.autilslev(name13);
		//
		// 顺序对应14个派出所
		int[] bindex={0,1,2,3,4,5,6,7,8,9,10,11,12};
		// 从小到大
		for(int i=0;i<bcnt.length-1;i++){   
               for(int j=i+1;j<bcnt.length;j++){   
                   if (bcnt[i]>bcnt[j]){   
                       long temp=bcnt[i];   
                       bcnt[i]=bcnt[j];   
                       bcnt[j]=temp; 
                       //下标
                       int tep=bindex[i];
                       bindex[i]=bindex[j];
                       bindex[j]=tep;
                  }   
            }  
       }  
		mv.addObject("bfirst",bcnt[12]);//最大数
		mv.addObject("bfirsta",this.aautils(bindex[12]));//对应单位名称
		mv.addObject("bsecond",bcnt[11]);
		mv.addObject("bseconda",this.aautils(bindex[11]));
		mv.addObject("bthird",bcnt[10]);
		mv.addObject("bthirda",this.aautils(bindex[10]));
		mv.addObject("bforth",bcnt[9]);
		mv.addObject("bfortha",this.aautils(bindex[9]));
		mv.addObject("bfifth",bcnt[8]);
		mv.addObject("bfiftha",this.aautils(bindex[8]));
		mv.addObject("bsixth",bcnt[7]);
		mv.addObject("bsixtha",this.aautils(bindex[7]));
		mv.addObject("bseventh",bcnt[6]);
		mv.addObject("bseventha",this.aautils(bindex[6]));
		mv.addObject("beighth",bcnt[5]);
		mv.addObject("beightha",this.aautils(bindex[5]));
		mv.addObject("bninth",bcnt[4]);
		mv.addObject("bnintha",this.aautils(bindex[4]));
		mv.addObject("btenth",bcnt[3]);
		mv.addObject("btentha",this.aautils(bindex[3]));
		mv.addObject("beleventh",bcnt[2]);
		mv.addObject("beleventha",this.aautils(bindex[2]));
		mv.addObject("btwelfth",bcnt[1]);
		mv.addObject("btwelftha",this.aautils(bindex[1]));
		mv.addObject("bthirteenth",bcnt[0]);
		mv.addObject("bthirteentha",this.aautils(bindex[0]));
//		mv.addObject("bforteenth",bcnt[0]);
//		mv.addObject("bforteentha",this.aautils(index[0]));
		
		
		String cname1="fzs",cname2="xzdd",cname3="zadd",cname4="gbdd",cname5="jjdc",cname6="zgs",cname7="xjdd",cname8="kss",cname9="wadd",cname10="crjgldd",cname11="jzdd",
				cname12="kgssk",cname13="jjdd",cname14="zgzx",cname15="xfdd",cname16="jwbzs",cname17="qbzx",cname18="zxjls",cname19="jddd",cname20="kjxxk",cname21="fkdd",cname22="hczzs";
		long[] fcnt=new long[22];
		// cnt[0]+cnt[1]=cnt指挥中心？？？只能直接新增zhzx
		fcnt[0]=this.associationsService.autils(cname1);
		fcnt[1]=this.associationsService.autils(cname2);
		fcnt[2]=this.associationsService.autils(cname3);
		fcnt[3]=this.associationsService.autils(cname4);
		fcnt[4]=this.associationsService.autils(cname5);
		fcnt[5]=this.associationsService.autils(cname6);
		fcnt[6]=this.associationsService.autils(cname7);
		fcnt[7]=this.associationsService.autils(cname8);
		fcnt[8]=this.associationsService.autils(cname9);
		fcnt[9]=this.associationsService.autils(cname10);
		fcnt[10]=this.associationsService.autils(cname11);
		fcnt[11]=this.associationsService.autils(cname12);
		fcnt[12]=this.associationsService.autils(cname13);
		fcnt[13]=this.associationsService.autils(cname14);
		fcnt[14]=this.associationsService.autils(cname15);
		fcnt[15]=this.associationsService.autils(cname16);
		fcnt[16]=this.associationsService.autils(cname17);
		fcnt[17]=this.associationsService.autils(cname18);
		fcnt[18]=this.associationsService.autils(cname19);
		fcnt[19]=this.associationsService.autils(cname20);
		fcnt[20]=this.associationsService.autils(cname21);
		fcnt[21]=this.associationsService.autils(cname22);
		//
		// 顺序对应14个派出所
		int[] findex={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21};
		// 从小到大
		for(int i=0;i<fcnt.length-1;i++){   
               for(int j=i+1;j<fcnt.length;j++){   
                   if (fcnt[i]>fcnt[j]){   
                       long temp=fcnt[i];   
                       fcnt[i]=fcnt[j];   
                       fcnt[j]=temp; 
                       //下标
                       int tep=findex[i];
                       findex[i]=findex[j];
                       findex[j]=tep;
                  }   
            }  
       }  
		mv.addObject("ffirst",fcnt[21]);//最大数
		mv.addObject("ffirsta",this.raautils(findex[21]));//对应单位名称
		mv.addObject("fsecond",fcnt[20]);
		mv.addObject("fseconda",this.raautils(findex[20]));
		mv.addObject("fthird",fcnt[19]);
		mv.addObject("fthirda",this.raautils(findex[19]));
		mv.addObject("fforth",fcnt[18]);
		mv.addObject("ffortha",this.raautils(findex[18]));
		mv.addObject("ffifth",fcnt[17]);
		mv.addObject("ffiftha",this.raautils(findex[17]));
		mv.addObject("fsixth",fcnt[16]);
		mv.addObject("fsixtha",this.raautils(findex[16]));
		mv.addObject("fseventh",fcnt[15]);
		mv.addObject("fseventha",this.raautils(findex[15]));
		mv.addObject("feighth",fcnt[14]);
		mv.addObject("feightha",this.raautils(findex[14]));
		mv.addObject("fninth",fcnt[13]);
		mv.addObject("fnintha",this.raautils(findex[13]));
		mv.addObject("ftenth",fcnt[12]);
		mv.addObject("ftentha",this.raautils(findex[12]));
		mv.addObject("feleventh",fcnt[11]);
		mv.addObject("feleventha",this.raautils(findex[11]));
		mv.addObject("ftwelfth",fcnt[10]);
		mv.addObject("ftwelftha",this.raautils(findex[10]));
		mv.addObject("fthirteenth",fcnt[9]);
		mv.addObject("fthirteentha",this.raautils(findex[9]));
		mv.addObject("fforteenth",fcnt[8]);
		mv.addObject("fforteentha",this.raautils(findex[8]));
		mv.addObject("ffifteenth",fcnt[7]);
		mv.addObject("ffifteentha",this.raautils(findex[7]));
		mv.addObject("fsixteenth",fcnt[6]);
		mv.addObject("fsixteentha",this.raautils(findex[6]));
		mv.addObject("fseventeenth",fcnt[5]);
		mv.addObject("fseventeentha",this.raautils(findex[5]));
		mv.addObject("feighteenth",fcnt[4]);
		mv.addObject("feighteentha",this.raautils(findex[4]));
		mv.addObject("fninteenth",fcnt[3]);
		mv.addObject("fninteentha",this.raautils(findex[3]));
		mv.addObject("ftweenty",fcnt[2]);
		mv.addObject("ftweentya",this.raautils(findex[2]));
		mv.addObject("ftweenOne",fcnt[1]);
		mv.addObject("ftweenOnea",this.raautils(findex[1]));
		mv.addObject("ftweenTwo",fcnt[0]);
		mv.addObject("ftweenTwoa",this.raautils(findex[0]));
		
		//统计采用了数据
		long[] bfcnt=new long[22];
		// cnt[0]+cnt[1]=cnt指挥中心？？？只能直接新增zhzx
		bfcnt[0]=this.associationsService.autilslev(cname1);
		bfcnt[1]=this.associationsService.autilslev(cname2);
		bfcnt[2]=this.associationsService.autilslev(cname3);
		bfcnt[3]=this.associationsService.autilslev(cname4);
		bfcnt[4]=this.associationsService.autilslev(cname5);
		bfcnt[5]=this.associationsService.autilslev(cname6);
		bfcnt[6]=this.associationsService.autilslev(cname7);
		bfcnt[7]=this.associationsService.autilslev(cname8);
		bfcnt[8]=this.associationsService.autilslev(cname9);
		bfcnt[9]=this.associationsService.autilslev(cname10);
		bfcnt[10]=this.associationsService.autilslev(cname11);
		bfcnt[11]=this.associationsService.autilslev(cname12);
		bfcnt[12]=this.associationsService.autilslev(cname13);
		bfcnt[13]=this.associationsService.autilslev(cname14);
		bfcnt[14]=this.associationsService.autilslev(cname15);
		bfcnt[15]=this.associationsService.autilslev(cname16);
		bfcnt[16]=this.associationsService.autilslev(cname17);
		bfcnt[17]=this.associationsService.autilslev(cname18);
		bfcnt[18]=this.associationsService.autilslev(cname19);
		bfcnt[19]=this.associationsService.autilslev(cname20);
		bfcnt[20]=this.associationsService.autilslev(cname21);
		bfcnt[21]=this.associationsService.autilslev(cname22);
		//
		// 顺序对应14个派出所
		int[] bfindex={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21};
		// 从小到大
		for(int i=0;i<bfcnt.length-1;i++){   
               for(int j=i+1;j<bfcnt.length;j++){   
                   if (bfcnt[i]>bfcnt[j]){   
                       long temp=bfcnt[i];   
                       bfcnt[i]=bfcnt[j];   
                       bfcnt[j]=temp; 
                       //下标
                       int tep=bfindex[i];
                       bfindex[i]=bfindex[j];
                       bfindex[j]=tep;
                  }   
            }  
       }  
		mv.addObject("bffirst",bfcnt[21]);//最大数
		mv.addObject("bffirsta",this.raautils(bfindex[21]));//对应单位名称
		mv.addObject("bfsecond",bfcnt[20]);
		mv.addObject("bfseconda",this.raautils(bfindex[20]));
		mv.addObject("bfthird",bfcnt[19]);
		mv.addObject("bfthirda",this.raautils(bfindex[19]));
		mv.addObject("bfforth",bfcnt[18]);
		mv.addObject("bffortha",this.raautils(bfindex[18]));
		mv.addObject("bffifth",bfcnt[17]);
		mv.addObject("bffiftha",this.raautils(bfindex[17]));
		mv.addObject("bfsixth",bfcnt[16]);
		mv.addObject("bfsixtha",this.raautils(bfindex[16]));
		mv.addObject("bfseventh",bfcnt[15]);
		mv.addObject("bfseventha",this.raautils(bfindex[15]));
		mv.addObject("bfeighth",bfcnt[14]);
		mv.addObject("bfeightha",this.raautils(bfindex[14]));
		mv.addObject("bfninth",bfcnt[13]);
		mv.addObject("bfnintha",this.raautils(bfindex[13]));
		mv.addObject("bftenth",bfcnt[12]);
		mv.addObject("bftentha",this.raautils(bfindex[12]));
		mv.addObject("bfeleventh",bfcnt[11]);
		mv.addObject("bfeleventha",this.raautils(bfindex[11]));
		mv.addObject("bftwelfth",bfcnt[10]);
		mv.addObject("bftwelftha",this.raautils(bfindex[10]));
		mv.addObject("bfthirteenth",bfcnt[9]);
		mv.addObject("bfthirteentha",this.raautils(bfindex[9]));
		mv.addObject("bfforteenth",bfcnt[8]);
		mv.addObject("bfforteentha",this.raautils(bfindex[8]));
		mv.addObject("bffifteenth",bfcnt[7]);
		mv.addObject("bffifteentha",this.raautils(bfindex[7]));
		mv.addObject("bfsixteenth",bfcnt[6]);
		mv.addObject("bfsixteentha",this.raautils(bfindex[6]));
		mv.addObject("bfseventeenth",bfcnt[5]);
		mv.addObject("bfseventeentha",this.raautils(bfindex[5]));
		mv.addObject("bfeighteenth",bfcnt[4]);
		mv.addObject("bfeighteentha",this.raautils(bfindex[4]));
		mv.addObject("bfninteenth",bfcnt[3]);
		mv.addObject("bfninteentha",this.raautils(bfindex[3]));
		mv.addObject("bftweenty",bfcnt[2]);
		mv.addObject("bftweentya",this.raautils(bfindex[2]));
		mv.addObject("bftweenOne",bfcnt[1]);
		mv.addObject("bftweenOnea",this.raautils(bfindex[1]));
		mv.addObject("bftweenTwo",bfcnt[0]);
		mv.addObject("bftweenTwoa",this.raautils(bfindex[0]));
		
		return mv;
	}


	
	  
	
	  /**
	   * 有效
	   * 市局
	   * 更多专题
	   */
	  @RequestMapping("more")
	  public ModelAndView loadMores() {
	    ModelAndView mv = new ModelAndView("/moreList.jsp");
	  //襄阳市公安局，需要加入当前时间段周数
	  		Date datetime = new Date();
	  		int weekdays = datetime.getDay();
	  		mv.addObject("weekdays",weekdays);
	  		
	    return mv;
	  }
	  
	  /**
	   * 有效
	   * 市局
	   * 更多应用系统
	   */
	  @RequestMapping("moreApps")
	  public ModelAndView loadMoreApps() {
	    ModelAndView mv = new ModelAndView("/appsList.jsp");
	  //襄阳市公安局，需要加入当前时间段周数
	  		Date datetime = new Date();
	  		int weekdays = datetime.getDay();
	  		mv.addObject("weekdays",weekdays);
	  		
	    return mv;
	  }
	  
	/**
	 * 清除掉全部数据缓存
	 * @return
	 */
	@RequestMapping("/clearCache")
	@CacheEvict(value = "cache1",allEntries=true)
	public String clearCache(){
	  return "ok...";
	}

  /**
   * 认证页面
   */
  @RequestMapping("verify")
  public ModelAndView verifyIndex() {
    ModelAndView mv = new ModelAndView("/verify.jsp");
    return mv;
  }
  
  /**
   * 个人中心 图片上传 upfileImg.jsp
   */
  @RequestMapping("upfileImg")
  public ModelAndView upfileImg() {
    ModelAndView mv = new ModelAndView("/upfileImg.jsp");
    return mv;
  }

  /**
   * 图片上传公共 upfileImg2.jsp
   */
  @RequestMapping("upfileImg2")
  public ModelAndView upfileImg2() {
    ModelAndView mv = new ModelAndView("/upfileImg2.jsp");
    return mv;
  }
  
  /**
   * 404页面
   */
  @RequestMapping("404")
  public ModelAndView notfond() {
    return new ModelAndView("/404.jsp");
  }
  /**
   * 500页面
   */
  @RequestMapping("500")
  public ModelAndView servicebusy() {
    return new ModelAndView("/500.jsp");
  }
  
  /**
   * 正在建设中页面
   */
  @RequestMapping("waiting")
  public ModelAndView waiting() {
    return new ModelAndView("/waiting.jsp");
  }
  
  
 
  /**
   * 有效：（utils）
   * 判断部门
   * @param index
   * @return
   */
  public String aautils(int index){
	  String name=null;
	  switch(index){
	  case 0:name = "张湾派出所";break;
	  case 1:name = "肖湾派出所";break;
	  case 2:name = "双沟派出所";break;
	  case 3:name = "程河派出所";break;
	  case 4:name = "朱集派出所";break;
	  case 5:name = "峪山派出所";break;
	  case 6:name = "张家集派出所";break;
	  case 7:name = "石桥派出所";break;
	  case 8:name = "黄龙派出所";break;
	  case 9:name = "古驿派出所";break;
	  case 10:name = "龙王派出所";break;
	  case 11:name = "伙牌派出所";break;
	  case 12:name = "黄集派出所";break;
	  }
	  return name;
  }
  
  /**
   * 有效：（utils）
   * 判断投稿地区
   * @param index
   * @return
   */
  public String raautils(int index){
	  String name=null;
	  switch(index){
	  case 0:name = "法制室";break;
	  case 1:name = "刑侦大队";break;
	  case 2:name = "治安大队";break;
	  case 3:name = "国保大队";break;
	  case 4:name = "纪检督察";break;
	  case 5:name = "政工室";break;
	  case 6:name = "巡警大队";break;
	  case 7:name = "看守所";break;
	  case 8:name = "网安大队";break;
	  case 9:name = "出入境管理大队";break;
	  case 10:name = "经侦大队";break;
	  case 11:name = "控告申诉科";break;
	  case 12:name = "交警大队";break;
	  case 13:name = "指挥中心";break;
	  case 14:name = "消防大队";break;
	  case 15:name = "警务保障室";break;
	  case 16:name = "情报中心";break;
	  case 17:name = "行政拘留所";break;
	  case 18:name = "禁毒大队";break;
	  case 19:name = "科技信息科";break;
	  case 20:name = "反恐大队";break;
	  case 21:name = "合成作战室";break;
	  }
	  return name;
  }
  
  /**
   * 有效：（utils）
   * 判断访问地区
   * @param index
   * @return
   */
  public String baautils(int index){
	  String name=null;
	  switch(index){
	  case 0:name = "襄城";break;
	  case 1:name = "樊城";break;
	  case 2:name = "高新";break;
	  case 3:name = "襄东";break;
	  case 4:name = "东津新区";break;
	  case 5:name = "鱼梁洲";break;
	  case 6:name = "襄州区";break;
	  case 7:name = "枣阳市";break;
	  case 8:name = "宜城市";break;
	  case 9:name = "老河口市";break;
	  case 10:name = "南漳县";break;
	  case 11:name = "保康县";break;
	  case 12:name = "谷城县";break;
	  }
	  return name;
  }
  
}
